package sdau.hjk.dao;

import org.apache.ibatis.annotations.Delete;
import sdau.hjk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *@version 1.0
 *@author: huangjiakai
 *@create:2021−02-05 16:38
 *@className:com.hjk.dao.IUserDao
 *@description: 用户dao接口
 */
@Repository
public interface IUserDao {
    //查询用户
    @Select("select * from user")
    public List<User> findAll();
    //根据openid查询
    @Select("select * from user_info where openid = #{openid}")
    public User findByOpenid(String openid);
    //根据班级查询
    @Select("select * from user where major = #{major} and grade = #{grade}")
    public List<User> findByGrade(@Param("major") String major, @Param("grade") String grade);
    //根据专业查询
    @Select("select * from user where major = #{major}")
    public List<User> findByMajor(String major);
    //根据学号查询
    @Select("select * from user where id = #{id}")
    public User findById(Integer id);
    //保存用户信息
    @Insert("insert into user(id,name,major,grade,phone) values(#{id},#{name},#{major},#{grade},#{phone})")
    public void saveUserInfo(User user);
    @Insert("insert into openid_id(openid,id) values(#{openid},#{id})")
    public void saveUser(User user);
    //删除用户信息
    @Delete("delete from user where id = #{id}")
    public void deleteUserInfo(Integer id);
    @Delete("delete from openid_id where id = #{id}")
    public void deleteUser(Integer id);

}
